/*
 * @lc app=leetcode.cn id=1496 lang=javascript
 *
 * [1496] 判断路径是否相交
 */

// @lc code=start
/**
 * @param {string} path
 * @return {boolean}
 */
var isPathCrossing = function (path) {
  const map = {
    N: [0, 1],
    E: [1, 0],
    S: [0, -1],
    W: [-1, 0]
  }
  const res = ['0,0'];
  let cur = [0, 0];
  path.split('').forEach(d => {
    const [dx, dy] = map[d];
    cur[0] += dx;
    cur[1] += dy;
    res.push(`${cur}`);
  });
  return res.length !== new Set(res).size;
};
// @lc code=end

